﻿#region File Description
//  XAEnima 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  File description: GUI
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using XAEnima.Core.GameManager;

namespace XAEnima.gui
{
    class UIentry : UIlabel
    {
        static int i = 0;
        Texture2D currentSkin;
        Texture2D activeSkin;
        Vector2 text_pos;
        bool oldstate = false;
        TextManager textManager;
        KeyboardState kstate, okstate;

        public UIentry(Vector2 p, string f, string s, string s1, Game Game)
            : base(f,Game)
        {
            textManager = new TextManager(Game);
            Game.Components.Add(textManager);
         textManager.APressed += new CharEventHandler(AIsPressed);
         textManager.BPressed += new CharEventHandler(BIsPressed);
         textManager.CPressed += new CharEventHandler(CIsPressed);
         textManager.DPressed += new CharEventHandler(DIsPressed);
         textManager.EPressed += new CharEventHandler(EIsPressed);
         textManager.FPressed += new CharEventHandler(FIsPressed);
         textManager.GPressed += new CharEventHandler(GIsPressed);
         textManager.HPressed += new CharEventHandler(HIsPressed);
         textManager.IPressed += new CharEventHandler(IIsPressed);
         textManager.LPressed += new CharEventHandler(LIsPressed);
         textManager.MPressed += new CharEventHandler(MIsPressed);
         textManager.NPressed += new CharEventHandler(NIsPressed);
         textManager.OPressed += new CharEventHandler(OIsPressed);
         textManager.PPressed += new CharEventHandler(PIsPressed);
         textManager.QPressed += new CharEventHandler(QIsPressed);
         textManager.RPressed += new CharEventHandler(RIsPressed);
         textManager.SPressed += new CharEventHandler(SIsPressed);
         textManager.TPressed += new CharEventHandler(TIsPressed);
         textManager.UPressed += new CharEventHandler(UIsPressed);
         textManager.VPressed += new CharEventHandler(VIsPressed);
         textManager.ZPressed += new CharEventHandler(ZIsPressed);
         textManager.WPressed += new CharEventHandler(WIsPressed);
         textManager.JPressed += new CharEventHandler(JIsPressed);
         textManager.KPressed += new CharEventHandler(KIsPressed);
         textManager.XPressed += new CharEventHandler(XIsPressed);
         textManager.YPressed += new CharEventHandler(YIsPressed);
         textManager.Pressed0 += new CharEventHandler(IsPressed0);
         textManager.Pressed1 += new CharEventHandler(IsPressed1);
         textManager.Pressed2 += new CharEventHandler(IsPressed2);
         textManager.Pressed3 += new CharEventHandler(IsPressed3);
         textManager.Pressed4 += new CharEventHandler(IsPressed4);
         textManager.Pressed5 += new CharEventHandler(IsPressed5);
         textManager.Pressed6 += new CharEventHandler(IsPressed6);
         textManager.Pressed7 += new CharEventHandler(IsPressed7);
         textManager.Pressed8 += new CharEventHandler(IsPressed8);
         textManager.Pressed9 += new CharEventHandler(IsPressed9);

         textManager.SpacePressed += new CharEventHandler(SpaceIsPressed);
         textManager.BackPressed += new CharEventHandler(BackIsPressed);
     
            ID = i;
            Name = "Entry" + ID;
            Position = p;
            font = Game.Content.Load<SpriteFont>(f);
            Skin = Game.Content.Load<Texture2D>(@s);
            activeSkin = Game.Content.Load<Texture2D>(@s1);
            currentSkin = Skin;
            i++;
        }
        public UIentry(String n, Vector2 p, String t, string f, string s, string s1, Game Game)
            : base(n,t,f,Game)
        {
            textManager = new TextManager(Game);
            Game.Components.Add(textManager);
            textManager.APressed += new CharEventHandler(AIsPressed);
            textManager.BPressed += new CharEventHandler(BIsPressed);
            textManager.CPressed += new CharEventHandler(CIsPressed);
            textManager.DPressed += new CharEventHandler(DIsPressed);
            textManager.EPressed += new CharEventHandler(EIsPressed);
            textManager.FPressed += new CharEventHandler(FIsPressed);
            textManager.GPressed += new CharEventHandler(GIsPressed);
            textManager.HPressed += new CharEventHandler(HIsPressed);
            textManager.IPressed += new CharEventHandler(IIsPressed);
            textManager.LPressed += new CharEventHandler(LIsPressed);
            textManager.MPressed += new CharEventHandler(MIsPressed);
            textManager.NPressed += new CharEventHandler(NIsPressed);
            textManager.OPressed += new CharEventHandler(OIsPressed);
            textManager.PPressed += new CharEventHandler(PIsPressed);
            textManager.QPressed += new CharEventHandler(QIsPressed);
            textManager = new TextManager(Game);
            ID = i;
            Name = n;
            text = t;
            Position = p;
            font = Game.Content.Load<SpriteFont>(f);
            font = Game.Content.Load<SpriteFont>(f);
            Skin = Game.Content.Load<Texture2D>(@s);
            activeSkin = Game.Content.Load<Texture2D>(@s1);
            currentSkin = Skin;
            i++;
            
        }

        private void CharIsPressed() { 
        
        }

        protected override void Dispose(bool disposing)
        {
            /*Skin.Dispose();
            activeSkin.Dispose();
            currentSkin.Dispose();*/
            Game.Services.RemoveService(typeof(UIentry));
            Game.Services.RemoveService(typeof(TextManager));
            Game.Components.Remove(textManager);
            base.Dispose(disposing);
        }
        
        public void UpdateButton(GameTime gameTime)
        {
            if (!oldstate && Select)
            {
                currentSkin = activeSkin;
                oldstate = true;
            }
            else if (oldstate && !Select)
            {
                currentSkin = Skin;
                oldstate = false;
            }
        }


        public Texture2D CurrentSkin {
            get { return currentSkin; }
            set { currentSkin = value; }
        }

        public Vector2 this[float f] {
            set { text_pos = new Vector2(f, Position.Y); }
            get { return text_pos; }
        }


        private void AIsPressed(){
            if(Select && Text.Length< 12){Text = Text+"a";}
        }

        private void BIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "b"; }
        }
        private void CIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "c"; }
        }
        private void DIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "d"; }
        }
        private void EIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "e"; }
        }
        private void FIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "f"; }
        }
        private void GIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "g"; }
        }
        private void HIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "h"; }
        }
        private void IIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "i"; }
        }
        private void LIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "l"; }
        }
        private void MIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "m"; }
        }
        private void NIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "n"; }
        }
        private void OIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "o"; }
        }
        private void PIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "p"; }
        }
        private void QIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "q"; }
        }
        private void RIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "r"; }
        }
        private void SIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "s"; }
        }
        private void TIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "t"; }
        }
        private void UIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "u"; }
        }
        private void VIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "v"; }
        }
        private void ZIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "z"; }
        }
        private void WIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "w"; }
        }
        private void JIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "j"; }
        }
        private void KIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "k"; }
        }
        private void XIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "x"; }
        }
        private void YIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "y"; }
        }
        private void IsPressed0() {
            if (Select && Text.Length < 12) { Text = Text + "0"; }
        }
        private void IsPressed1()
        {
            if (Select && Text.Length < 12) { Text = Text + "1"; }
        }
        private void IsPressed2()
        {
            if (Select && Text.Length < 12) { Text = Text + "2"; }
        }
        private void IsPressed3()
        {
            if (Select && Text.Length < 12) { Text = Text + "3"; }
        }
        private void IsPressed4()
        {
            if (Select && Text.Length < 12) { Text = Text + "4"; }
        }
        private void IsPressed5()
        {
            if (Select && Text.Length < 12) { Text = Text + "5"; }
        }
        private void IsPressed6()
        {
            if (Select && Text.Length < 12) { Text = Text + "6"; }
        }
        private void IsPressed7()
        {
            if (Select && Text.Length < 12) { Text = Text + "7"; }
        }
        private void IsPressed8()
        {
            if (Select && Text.Length < 12) { Text = Text + "8"; }
        }
        private void IsPressed9()
        {
            if (Select && Text.Length < 12) { Text = Text + "9"; }
        }
        private void SpaceIsPressed()
        {
            if (Select && Text.Length < 12) { Text = Text + "_"; }
        }
        private void BackIsPressed()
        {
            if (Select && Text.Length>0) { int p = Text.Length; Text = Text.Substring(0, p - 1); }
        }
    }
}
